package com.icoolkj.ms.rbac.controller;

import com.icoolkj.ms.api.auth.bo.UserInfoInTokenBO;
import com.icoolkj.ms.common.core.response.MapBean;
import com.icoolkj.ms.common.core.response.ServerResponseEntity;
import com.icoolkj.ms.common.security.AuthUserContext;
import com.icoolkj.ms.rbac.service.ISysPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * @author icoolkj
 * @version 1.0
 * @description 用户信息
 * @createDate 2025/02/16 18:56
 */
@RestController
public class SysUserController {

    @Autowired
    private ISysPermissionService iSysPermissionService;

    @GetMapping("getInfo")
    public ServerResponseEntity<MapBean> getInfo() {
        MapBean mapBean = new MapBean();
        UserInfoInTokenBO userInfoInTokenBO = AuthUserContext.get();
        mapBean.withParameter("user", userInfoInTokenBO);
        List<String> permission = iSysPermissionService.getUserMenuPermissions(userInfoInTokenBO.getUserId(), 
                userInfoInTokenBO.getUserType());
        mapBean.withParameter("permission", permission);
        List<String> roles = iSysPermissionService.selectRoleKeyListByUserId(userInfoInTokenBO.getUserId(), 
                userInfoInTokenBO.getUserType());
        mapBean.withParameter("roles", roles);
        return ServerResponseEntity.success(mapBean);
    }

}
